package com.by.controller;


import com.by.bean.ResultBean;
import com.by.ex.BusinessException;
import com.by.ex.DatabaseException;
import com.by.ex.ValidateException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.xml.bind.ValidationException;

@RestControllerAdvice//异常增强注解
public class GlobalExceptionController extends BaseController{

    @ExceptionHandler(ValidateException.class)
    public ResultBean handlerValidationException(ValidateException e){
        return fail("验证失败",e.getErrorMap());
    }

    @ExceptionHandler(BusinessException.class)
    public ResultBean handlerBusinessException(BusinessException e){
        return fail("业务异常",e.getMessage());
    }

    @ExceptionHandler(DatabaseException.class)
    public ResultBean handlerDatabaseException(DatabaseException e){
        return fail("数据库异常",e.getMessage());
    }
}
